<?php
// Classe de base des éléments de template
abstract class PexElement{
    public abstract function imprimer();
    public abstract function evaluer(&$substitutions = array());
    public abstract function ajouter($data);
    public abstract function type();

    public function replace($substitutions, $texte){
        if (trim($texte) == '' /* || count($substitutions) == 0 */) return $texte;

        $val = &$texte;

        // Cas spécial des variables conditionnelles
        foreach(Parseur::$VARIABLES_CONDITIONNELLES as $varcond)
        {
	        if (isset($substitutions['#__VARCOND__'.$varcond.'__']))
	        {
	            $num_exp = $substitutions['#__VARCOND__'.$varcond.'__'] == '1' ? '1' : '2';

		 		$val = preg_replace('/#'.$varcond.'\[([^]]*)\]\[([^]]*)\]/', "\\$num_exp", $texte);
	        }
        }

        $subs = str_replace(array_keys($substitutions), array_values($substitutions), $val);

        // Traiter les variables de template s'il y en a
        if (strpos($subs, '#SET') !== false || strpos($subs, '#GET') !== false || strpos($subs, '#ENV') !== false || strpos($subs, '#SESSION') !== false)
        {
        	include_once(realpath(dirname(__FILE__)).'/VariablesTemplate.class.php');

        	$subs = VariablesTemplate::analyser($subs);
        }

        return $subs;
    }
}

?>